<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // ES6中新增剩余参数，形式为...形参，用于获取多余的参数
        function f1(...nums){
            console.log(nums);
        }
        f1(10,20,30);
        f1("aa","bb","cc","dd","ee");

        function f2(a,...b){
            console.log(a);
            console.log(b);
        }
        f2(10,200,300,400);
        f2("aa","bb","cc");

        //剩余参数必须是最后一个参数，否则会报错
        function f3(a,...b){
            console.log(a);
            console.log(b);
        }
        f3("aaa","bbb","ccc");


        //有了rest剩余参数在这个位置可以代替arguments
        function calcSum(...nums){
            let sum=0;
            for(var i=0;i<nums.length;i++){
                sum+=nums[i];
            }
            console.log(sum);
        }
        calcSum(100,200,300,400);
        calcSum(100,200);
    </script>
</head>
<body>
    
</body>
</html>